package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.VideoManager;
import com.itheima.domain.mongo.Video;
import com.itheima.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class VideoController {

    @Autowired
    private VideoManager videoManager;


    //小视频列表
    @GetMapping("/smallVideos")
    public ResponseEntity smallVideos(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) throws IOException {
        Long localUserId = UserHolder.getLocalUserId();
        PageBeanVo pageBeanVo = videoManager.smallVideos(localUserId, page, pagesize);
        return ResponseEntity.ok(pageBeanVo);
    }


    @PostMapping("/smallVideos")
    public ResponseEntity publishVideo(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {
        Long localUserId = UserHolder.getLocalUserId();
        return videoManager.publishVideo(localUserId,videoThumbnail,videoFile);
    }
//视频用户关注
    @PostMapping("/smallVideos/{focusUserId}/userFocus")
    public ResponseEntity userFocus(@PathVariable Long focusUserId){
        return videoManager.userFocus(focusUserId);

    }

    //视频用户关注
    @PostMapping("/smallVideos/{focusUserId}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable Long focusUserId){
        return videoManager.userUnFocus(focusUserId);

    }
}
